package com.wanxi.servlet;

import com.wanxi.model.ImageShowModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.ProductModel;
import com.wanxi.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/product")
public class ProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        数据给服务端处理
        ProductService productService=new ProductService();
        List<NavModel> navModelList=new ArrayList<>();
        List<NavModel> productNavModelList=new ArrayList<>();
        List<ImageShowModel> productImageModelList=new ArrayList<>();
        List<ProductModel> productModelList=new ArrayList<>();

        navModelList=productService.getNavModelList();
        productNavModelList=productService.getProductNavModelList();
        productImageModelList=productService.getProductImageModelList();
        productModelList=productService.getProductModelList();
//        数据存储
        req.setAttribute("navModelList",navModelList);
        req.setAttribute("productImageModelList",productImageModelList);
        req.setAttribute("productModelList",productModelList);
        req.setAttribute("productNavModelList",productNavModelList);

//        页面转发
        req.getRequestDispatcher("page/product.jsp").forward(req,resp);
    }
}
